﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.BLL;
using COM.OA.Entity;
using COM.OA.DBFactory;
using System.Collections.Generic;

public partial class rlzy_lrda : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //登录时插数据库 编号+1
        IList<employee> l = employeeBLL.Select();
        //没有数据
        if (l.Count == 0)
        {
            this.txtNumber.Text = "10001";
        }
        else
        {
            List<employee> list = (List<employee>)l;
            employee em = new employee();
            em = list[0];
            int i = Int32.Parse(em.em_number);
            int num = i + 1;
            this.txtNumber.Text = num.ToString();
        }

        users loginuser = Session["loginuser"] as users;
        int Loginid = 0 ;
        string Loginname ="" ;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.ALLREDIRECT, "../login.aspx"));
        }
        else
        {
            Loginid = loginuser.u_em_id;
            string where = "em_id=" + Loginid;
            IList<employee> il = employeeBLL.Select(where);
            List<employee> ll = (List<employee>)il;
            employee em = new employee();
            em = ll[0];
            Loginname = em.em_name;
        }

        this.txtBookerid.Text = Loginname;

    }
    protected void btnRefer_Click(object sender, EventArgs e)
    {
        //取页面数据
        string Number = this.txtNumber.Text;//编号 
        string Name = this.txtName.Text;//姓名
        string EverName = this.txtEverName.Text;//曾用名
        int Gender = Int32.Parse(this.ddGender.Text);//性别
        string Marriage = this.txtMarriage.Text;//婚姻状况
        int Native = Int32.Parse(this.ddNative.Text);//籍贯
        int Province = Int32.Parse(this.ddProvince.Text);//户口所在地
        int Nation = Int32.Parse(this.ddNation.Text);//民族 
        DateTime Birth;//出生日期 如果空 给默认值
        string bi = this.wdBirth.Text;
        if (bi == "")
        {
            Birth = DateTime.Parse("1753-01-01");
        }
        else
        {
            Birth = DateTime.Parse(this.wdBirth.Text);
        }
        string Stature = this.txtStature.Text;//身高 
        string Avoirdupois = this.txtAvoirdupois.Text;//体重 
        int Visage = Int32.Parse(this.ddVisage.Text);//政治面貌
        string Statuscard = this.txtStatuscard.Text;//身份证号
        string Health = this.txtHealth.Text;//健康状况
        string Bloodtype = this.txtBloodtype.Text;//血型
        string Phone = this.txtPhone.Text;//目前电话
        string Mobile = this.txtMobile.Text;//手机
        string eMail = this.txtEMail.Text;//邮箱
        string FinishSchool = this.txtFinishSchool.Text;//毕业学校
        string Speciality = this.txtSpeciality.Text;//专业
        int Learn = Int32.Parse(this.ddLearn.Text);//学历
        DateTime Graduatetime;//毕业日期 如果空 给默认值
        string t = this.wdGraduatetime.Text;
        if (t == "")
        {
            Graduatetime = DateTime.Parse("1753-01-01");
        }
        else
        {
            Graduatetime = DateTime.Parse(this.wdGraduatetime.Text);
        }
        string Degree = this.txtDegree.Text; //学位
        string Language = this.txtLanguage.Text;//外语语种
        string LanguageLevel = this.txtLanguageLevel.Text;//外语水平
        string LanguageLetter = this.txtLanguageLetter.Text;//外语证书
        string ComputerLevel = this.txtComputerLevel.Text;//计算机水平
        string ComputerLetter = this.txtComputerLetter.Text;//计算机证书
        string ComputerGood = this.txtComputerGood.Text; //计算机特长
        string MandarinLevel = this.txtMandarinLevel.Text;//普通话水平
        string Familyaddress = this.txtFamilyaddress.Text;//家庭住址
        string Postalcode = this.txtPostalcode.Text; //邮编
        string Address = this.txtAddress.Text;//现住址
        string FamilyPhone = this.txtFamilyPhone.Text;//家庭电话
        string Addresspostalcode = this.txtAddresspostalcode.Text;//住址邮编
        string Familycircs = this.txtFamilycircs.Text;//家庭情况
        string RecordLocus = this.txtRecordLocus.Text;//档案存放地
        string JobName = this.txtJobName.Text;//职称
        string WhenJoinWork = this.txtWhenJoinWork.Text;//何时参加工作
        string WhenThisWork = this.txtWhenThisWork.Text;//何时到本单位
        string Addlength = this.txtAddlEngth.Text;//累计工龄
        string ThisUnitLength = this.txtThisUnitLength.Text;//本单位工龄
        int Department = Int32.Parse(this.ddDepartment.Text);//所在部门
        string Buty = this.txtButy.Text;//职务
        string Remark = this.txtRemark.Text;//备注
        DateTime Registertime = DateTime.Now;//时间
        //int Bookerid = Int32.Parse(this.txtBookerid.Text);//录入人ID


        employee em = new employee();
        em.em_number = Number;
        em.em_name = Name;
        em.em_evername = EverName;
        em.em_gender = Gender;
        em.em_marriage = Marriage;
        em.em_birth = Birth;
        em.em_n_id = Native;
        em.em_na_id = Nation;
        em.em_p_id = Province;
        em.em_stature = Stature;
        em.em_avoirdupois = Avoirdupois;
        em.em_v_id = Visage;
        em.em_statuscard = Statuscard;
        em.em_health = Health;
        em.em_bloodtype = Bloodtype;
        em.em_phone = Phone;
        em.em_mobile = Mobile;
        em.em_email = eMail;
        em.em_finishschool = FinishSchool;
        em.em_speciality = Speciality;
        em.em_l_id = Learn;
        em.em_graduatetime = Graduatetime;
        em.em_degree = Degree;
        em.em_language = Language;
        em.em_languageletter = LanguageLetter;
        em.em_languagelevel = LanguageLevel;
        em.em_computerlevel = ComputerLevel;
        em.em_computerletter = ComputerLetter;
        em.em_computergood = ComputerGood;
        em.em_mandarinlevel = MandarinLevel;
        em.em_familyaddress = Familyaddress;
        em.em_postalcode = Postalcode;
        em.em_address = Address;
        em.em_familyphone = FamilyPhone;
        em.em_familyaddress = Familyaddress;
        em.em_familyphone = FamilyPhone;
        em.em_addresspostalcode = Addresspostalcode;
        em.em_familycircs = Familycircs;
        em.em_recordlocus = RecordLocus;
        em.em_jobname = JobName;
        em.em_whenjoinwork = WhenJoinWork;
        em.em_whenthiswork = WhenThisWork;
        em.em_addlength = Addlength;
        em.em_thisunitlength = ThisUnitLength;
        em.em_dept_id = Department;
        em.em_duty = Buty;
        em.em_remark = Remark;
        //录入人id  当前登录用户
        users luser = Session["loginuser"] as users;
        em.em_bookerid = luser.u_id;
        //录入时间
        em.em_registertime = DateTime.Now;

        int i = employeeBLL.Insert(em);
        if (i > 0)
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "添加失败!"));
        }
        else
        {
            this.Response.Write(string.Format(GetRedirect.WINALERT, "添加成功!"));
            //如果添加成功，向user表中加入登陆相关信息
            IList<employee> l = employeeBLL.Select();
            List<employee> list = (List<employee>)l;
            employee emp = new employee();
            emp = list[0];
            string loginName = this.txtlonig.Text;//登陆名
            string loginPW = "66666";//密码
            DateTime logintime = DateTime.Now;//时间
            int bid = em.em_dept_id;//部门
            int daid = emp.em_id;//档案
            users u = new users();
            u.u_dept_id = bid;
            u.u_em_id = daid;
            u.u_logintime = logintime;
            u.u_password = loginPW;
            u.u_username = loginName;
            u.u_g_id = 1;
            usersBLL.Insert(u);
            this.Response.Write(string.Format(GetRedirect.REDIRECT, "dagl.aspx"));
        }

        //登陆名  密码 登陆时间 部门ID  档案ID
    }

}
